<?php
/**
*  Create On 2014-12-05
*  Author yiwei
*  QQ:1006629314
**/
class homework_period extends Model{
	private $table="xdf_homework_period";
	
	public function addHomeworkPeriod($homework_id,$period_id,$publish_type,$publish_time = null){
		$sql = 'INSERT INTO `'.$this->table.'` (`homework_id`,`period_id`,
				`publish_type`,`publish_time`,`create_time`) VALUES ('.$homework_id.',
				'.$period_id.','.$publish_type.',"'.$publish_time.'",NOW())';
		return $this->insert($sql);
	}
	
	public function getHomeworkPeriod($homework_id){
		$sql = 'SELECT `id`,`period_id`,`publish_type`,`publish_time` FROM `'.$this->table.'` WHERE `homework_id` = '.$homework_id;
		return $this->fetchAll($sql);
	}
	
	public function modifyHomeworkPeriod($period_id,$homework_id,$publish_type,$publish_time){
		$sql = 'UPDATE `'.$this->table.'` SET 
				`homework_id` = "'.$homework_id.'",
				`publish_type` = "'.$publish_type.'",
				`publish_time` = "'.$publish_time.'",
				`create_time` = NOW()
				WHERE `period_id` = '.$period_id;
		return $this->update($sql);
	}
	
	public function delHomeworkPeriod($id){
		$sql = 'DELETE FROM `'.$this->table.'` WHERE `id` = '.$id;
		return $this->del($sql);
	}
	
	public function getIdByPeriodId($period_id){
		$sql = 'SELECT id FROM`'.$this->table.'` WHERE `period_id` = '.$period_id;
		return $this->fetchRow($sql);
	}
	
	public function delHomeworkPeriodByPeriodId($period_id){
		$sql = 'DELETE FROM `'.$this->table.'` WHERE `period_id` = '.$period_id;
		return $this->del($sql);
	}
	
	public function publishHomeworkPeriod($id){
		$sql = 'UPDATE `'.$this->table.'` SET `publish_type` = 3 WHERE `id` = '.$id;
		return $this->update($sql);
	}
	//student get homework id by period id
	public function getHomeworkIdByPeriod($period_id){
		$sql = "SELECT homework_id FROM `$this->table` WHERE `period_id` = '$period_id' AND `publish_type`='3'";
		return $this->fetchRow($sql);
	}
	 
}